//
//  YTVideoView.m
//  YUNT
//
//  Created by 梁炜东 on 2017/11/9.
//  Copyright © 2017年 梁炜东. All rights reserved.
//

#import "YTVideoView.h"

@interface YTVideoView ()
/*
 控件
 */
@property(nonatomic, strong)UIImageView *focusImage;
/*
 业务相关属性
 */
@property(nonatomic, strong)dispatch_source_t focusTimer;
@end

@implementation YTVideoView
-(instancetype)init
{
    self = [super init];
    if (self)
    {
        self.frame = [UIScreen mainScreen].bounds;
        [self p_addSubviews];
        [self p_makeConstraints];
        [self p_addGes];
        [deviceManager configInitView:self];
    }
    return self;
}
-(void)p_addSubviews
{
    [self addSubview:self.focusImage];
}
-(void)p_makeConstraints
{
//    [_focusImage ]
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    [deviceManager configOrientation];
}
-(void)p_addGes
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    tap.numberOfTapsRequired = 1;
    tap.numberOfTouchesRequired = 1;
    [self addGestureRecognizer:tap];
}
#pragma mark tapAction
-(void)tapAction:(UITapGestureRecognizer *)tap
{
    if (tap.state == UIGestureRecognizerStateRecognized)
    {
        CGPoint location = [tap locationInView:self];
        [deviceManager clickScreenFoucs:location];
        _focusImage.hidden = NO;
        _focusImage.center = location;
        if (_focusTimer)
        {
            dispatch_cancel(_focusTimer);
            _focusTimer = nil;
        }
        _focusTimer = [YTTools gcdTimer:1 DelayTime:1.5];
        dispatch_source_set_event_handler(_focusTimer, ^{
            _focusImage.hidden = YES;
            if (_focusTimer)
            {
                dispatch_cancel(_focusTimer);
                _focusTimer = nil;
            }
        });
        dispatch_resume(_focusTimer);
    }
}
-(UIImageView *)focusImage
{
    if (!_focusImage)
    {
        _focusImage = [[UIImageView alloc] init];
        _focusImage.frame = CGRectMake(self.center.x, self.center.y, 234/2, 168/2);
        _focusImage.image = IMAGE(@"15");
        _focusImage.hidden = YES;
    }
    return _focusImage;
}
@end
